#include <stdio.h>

char s[20];
int N, R;
int now;

int main()
{
    int j = 0;

    scanf("%d%d", &N, &R);
    if(N < 0) {
        printf("-");
        N = -N;
    }

    while(N) {
        now = N % R;
        
        if(now < 10) {
            s[j++] = now + '0';
        } else {
            s[j++] = now + 'A' - 10;
        }
        N = N / R;
    }
    
    if(j == 0) {
        printf("0\n");
    }
    
    for(int i = j - 1; i >= 0; i--) {
        printf("%c", s[i]);
    }
    printf("\n");

    return 0;
}

